home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 May / macformat-050.iso / Shareware Plus / Developers / Find_icon folder / Sources / Get1IconSuite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-25  |  2.6 KB  |  98 lines  |  [TEXT/CWIE]

  1. /*    ---------------------------------------------------------------------------------------------
  2.     Find_icon, code for constructing icon suites for files and folders
  3.     
  4.     by James W. Walker
  5.     preferred e-mail: <mailto:jwwalker@kagi.com>
  6.     alternate e-mail: <mailto:jwwalker@aol.com>, <jim@nisus-soft.com>
  7.     web: <http://users.aol.com/jwwalker/>
  8.     
  9.     File: Get1IconSuite.c
  10.     
  11.     Copyright ©1997 by James W. Walker
  12.     
  13.     You may incorporate this sample code into your applications without
  14.     restriction, though the sample code has been provided "AS IS" and the
  15.     responsibility for its operation is 100% yours.
  16.     If you're going to re-distribute the source, please make it clear
  17.     that the code was descended from James W. Walker's code,
  18.     but that you've made changes.
  19.     ---------------------------------------------------------------------------------------------
  20. */
  21. #include "cheap-exceptions.h"
  22. #include <Errors.h>
  23. #include <Resources.h>
  24. #include "Get1IconSuite.h"
  25.  
  26. /*    --------------------------------------------------------------------
  27.     Get1IconSuite            Like GetIconSuite, but only looks in
  28.                             the current resource file.
  29.     
  30.     In case you're wondering why it would be necessary to ensure that
  31.     icons come from only one file, suppose you're looking at a
  32.     file that has its custom icon bit set, but for some reason does
  33.     not contain a custom icon, or at least not a full family.
  34.     Way down the resource chain, there may be another file, say a
  35.     font file, that does have a full family of custom icons. 
  36.     So you get an unexpected icon.
  37.     --------------------------------------------------------------------
  38. */
  39.  
  40. typedef struct {
  41.     short    res_ID;
  42.     Boolean    has_mask;
  43. } Loop_data;
  44.  
  45. static pascal OSErr Get_1_icon(
  46. /* --> */    ResType the_type,
  47. /* <-> */    Handle *the_icon,
  48. /* --> */    Loop_data    *data );
  49.  
  50.  
  51. pascal OSErr Get1IconSuite(
  52. /* <-- */    Handle *theSuite,
  53. /* --> */    short theID,
  54. /* --> */    IconSelectorValue theSelector
  55. )
  56. {
  57.     OSErr        err;
  58.     Loop_data    data;
  59.     IconActionUPP    get_icon_UPP;
  60.     
  61.     err = NewIconSuite( theSuite );
  62.     forbid( err, NewIconSuite );
  63.     
  64.     data.res_ID = theID;
  65.     data.has_mask = false;
  66.     get_icon_UPP = NewIconActionProc( Get_1_icon );
  67.     
  68.     err = ForEachIconDo( *theSuite, theSelector,
  69.         get_icon_UPP, &data );
  70.     
  71.     DisposeRoutineDescriptor( get_icon_UPP );
  72.     if ( (err == noErr) && (data.has_mask == false) )
  73.     {
  74.         err = noMaskFoundErr;
  75.         DisposeIconSuite( *theSuite, false );
  76.         *theSuite = NULL;
  77.     }
  78.     
  79. NewIconSuite:
  80.     return err;
  81. }
  82.  
  83. static pascal OSErr Get_1_icon(
  84. /* --> */    ResType the_type,
  85. /* <-> */    Handle *the_icon,
  86. /* <-> */    Loop_data    *data )
  87. {
  88.     *the_icon = Get1Resource( the_type, data->res_ID );
  89.     
  90.     if ( (*the_icon != NULL)
  91.         && ((the_type == 'ICN#') || (the_type == 'ics#') ))
  92.     {
  93.         data->has_mask = true;
  94.     }
  95.     
  96.     return noErr;
  97. }
  98.